<template>
	<scroll-view style="background-color: #f2f5f7;">
		<view style="width: 100%;" v-for="(item,index) in favoriteInfo.articleId">
			<view class="userItem" :key="index"
				style="height: 400rpx;background-color:white;margin-top:20rpx;margin-left: 10rpx;margin-right: 10rpx;margin-bottom: 20rpx;border-radius: 50rpx;padding-top: 30rpx;">
				<view style="display: flex;align-items: center;padding-left: 50rpx;margin-bottom: 30rpx;">
					<!-- 头像渲染 -->
					<image :src="imgUrlConfig+item.userId.img[0]" v-if="(!userImg(item.userId.img[0]))" mode="" style="width: 50rpx;height: 50rpx;"></image>
					<image :src="item.userId.img[0]" v-if="userImg(item.userId.img[0])" mode="" style="width: 50rpx;height: 50rpx;"></image>
					<span
						style="display: inline-block;padding-left: 12rpx;font-weight: bold;font-size:28rpx ;line-height:50rpx;">{{item.userId.nickName}}</span>
				</view>
				<view style="display: flex;align-items:center;justify-content: space-around;">
					<image :src="imgUrlConfig+item.img[0]" mode=""
						style="width: 200rpx;height: 200rpx; border-radius: 30rpx;"></image>
					<view style="width: 320rpx;">
						<p style="display: inline-block;font-size: 28rpx;width:320rpx;height:200rpx;font-weight:blod;">
							{{item.desc.substring(0,20)+"..."}}
						</p>
						
				
					</view>
					<view style="text-align: center;width: 100rpx;">
						<p style="font-size: 28rpx;"><span style="font-size: 24rpx;">￥</span><span
								style="color:red;">{{item.price}}</span></p>
					</view>
		
				</view>
				<view style="display: flex;flex-direction: row-reverse;padding-right: 20rpx;">
					<view @click="lookInfo(item._id,item)"
						style="margin-top:20rpx;display: inline-block;display:flex;width:160rpx;background-color:#78cdd1;border-radius:26rpx;line-height:60rpx;justify-content: center;font-size: 26rpx;">
						查看详情</view>
				</view>
			</view>
		</view>
			
		</view>
	</scroll-view>
</template>

<script>
	import timeFun from '../../utils/time.js'
	export default {
		created() {
			const userNow=this.$store.state.user;
			this.userInfo=userNow;
			console.log(this.userInfo._id);
			uni.request({
				url:`http://localhost:3001/favorites/find/userId=${this.userInfo._id}`,
				method:'GET',
				success: (res) => {
					this.favoriteInfo=res.data[0];
					console.log(this.favoriteInfo.articleId)
				}
			})
		}
		,
		data() {
			return {
				favoriteInfo:{},
				imgUrlConfig: 'http://localhost:3002',
			}
		},
		methods: {
			// 传入时间戳获得多少天前
			timingRen(time) {
				return timeFun.getFormatTime((new Date(time)).getTime());
			},
			// 判断图片src是否为http开头
			userImg(url){
				var str=new RegExp("http");
				return str.test(url)
			},
			lookInfo(id,artData){
				this.$store.commit('addGoods',artData);
				uni.navigateTo({
				        url: '/pages/goodsInfo/goodsInfo?_id='+artData._id
				      });
			}
		}
	}
</script>

<style>

</style>
